package tree;

public class SymmetricTree101 extends XTree {

    //    private int[] arr = new int[]{1, 2, 2, 2, NULL, 2};
    private int[] arr = new int[]{1, 2, 2, 3, 4, 4, 3};

    public static void main(String[] args) {
        SymmetricTree101 s = new SymmetricTree101();
        s.test();
    }

    // 模拟测试框架
    public void test() {
        TreeNode treeNode = createTreeNode(arr);
        Solution solution = new Solution();
        traverseLevel(treeNode);
        //TODO ADD
        System.out.println(solution.isSymmetric(treeNode));

    }


    // 提交到leetCode平台代码
    class Solution {

        public boolean isSymmetric(TreeNode root) {
            return check(root, root);
        }

        private boolean check(TreeNode p, TreeNode q) {
            if (p == null && q == null) {
                return true;
            }

            if (p == null || q == null) {
                return false;
            }

            return (p.val == q.val) && check(p.left, q.right) && check(q.left, p.right);
        }

    }
}


